package com.thread;


import java.util.concurrent.TimeUnit;

/**
 * final 修饰锁对象，不变，以免其他地方修改了对象锁  对象上的MarkWord
 */
public class ThreadLockObject012 {

    /*final*/  Object o = new Object();

    void m(){
        synchronized (o){
            while(true){

                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+" invoked...");
            }
        }
    }

    public static void main(String[] args) {
        ThreadLockObject012 t = new ThreadLockObject012();
        new Thread(t::m,"t1").start();;

        new Thread(t::m,"t2").start();;

        //t.o = new Object();// 这里对象不改变，t2线程永远得不到机会


    }

}
